package com.wlr.study.leetcode;

import java.util.LinkedList;
import java.util.List;

/**
 * 二叉树的最大深度
 *
 * @author lrwang
 * @version 1.0
 * @date 2022/4/6 22:07
 */
public class LeetCode104 {
    List<Integer> list = new LinkedList<>();

    public int maxDepth(TreeNode root) {
        int depth = 0;
        if (root == null) {
            return 0;
        } else {
            int leftDepth = maxDepth(root.left);
            int rightDepth = maxDepth(root.right);
            depth = 1 + Math.max(leftDepth, rightDepth);
        }
        return depth;
    }

    public static void main(String[] args) {
        LeetCode104 leetcode104 = new LeetCode104();
        TreeNode root = new TreeNode(3);
        TreeNode root1 = new TreeNode(0);
        TreeNode rootL = new TreeNode(9);
        TreeNode rootR = new TreeNode(20);
        TreeNode rootRl = new TreeNode(15);
        TreeNode rootRr = new TreeNode(7);
        root.left = rootL;
        rootR.left = rootRl;
        rootR.right = rootRr;
        root.right = rootR;
        System.out.println(leetcode104.maxDepth(root));
    }
}
